using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Sudoku.Lang;
using Services;
#if !SUDOKU_MASTER
	using Microsoft.Advertising.Mobile.Xna;
#endif

namespace Sudoku.Menu
{
	public class DifficultyScene : ExtendedGameComponent
	{
		Texture2D bg;

#if !SUDOKU_MASTER
		AdManager adManager;
#endif

		public DifficultyScene(Game game)
			: base(game)
		{
#if !SUDOKU_MASTER
			adManager = game.Services.GetService(typeof(AdManager)) as AdManager;
#endif
		}

		public override void Initialize()
		{
			bg = textureService.Background("General");
			SpriteFont font = fontService.Font(FontType.Delicious26Bold);

			soundService.TurnPageSound();

			LabelButton beginnerBtn = new LabelButton(Game, new Rectangle(20, 25, 185, 85), LocalizedStrings.MenuBeginner, font, Color.White);
			beginnerBtn.Texture = textureService.Texture("Button2");
			beginnerBtn.OnTap += (Button sender) => { StateManagement.StateManager.StartLevel(Game, GamePlay.Difficulty.Beginner); };
			Components.Add(beginnerBtn);

			LabelButton normalBtn = new LabelButton(Game, new Rectangle(20, 110, 185, 85), LocalizedStrings.MenuNormal, font, Color.White);
			normalBtn.Texture = textureService.Texture("Button2");
			normalBtn.OnTap += (Button sender) => { StateManagement.StateManager.StartLevel(Game, GamePlay.Difficulty.Normal); };
			Components.Add(normalBtn);

			LabelButton expBtn = new LabelButton(Game, new Rectangle(20, 195, 185, 85), LocalizedStrings.MenuExperienced, font, Color.White);
			expBtn.Texture = textureService.Texture("Button2");
			expBtn.OnTap += (Button sender) => { StateManagement.StateManager.StartLevel(Game, GamePlay.Difficulty.Experienced); };
			Components.Add(expBtn);

			LabelButton extrBtn = new LabelButton(Game, new Rectangle(20, 280, 185, 85), LocalizedStrings.MenuExtreme, font, Color.White);
			extrBtn.Texture = textureService.Texture("Button2");
			extrBtn.OnTap += (Button sender) => { StateManagement.StateManager.StartLevel(Game, GamePlay.Difficulty.Extreme); };
			Components.Add(extrBtn);

			var inputService = Game.Services.GetService(typeof(IInputManager)) as IInputManager;
			inputService.OnBack += new InputManager.PhoneButtonEvent(Back);

			base.Initialize();
		}

#if !SUDOKU_MASTER
		protected override void LoadContent()
		{
			adManager.CreateAd("36001", new Rectangle(0, 720, 480, 80), RotationMode.Automatic);

			base.LoadContent();
		}

		protected override void UnloadContent()
		{
			adManager.RemoveAll();

			base.UnloadContent();
		}
#endif

		private void Back()
		{
			soundService.PlaySound(SoundType.Fumble);
			StateManagement.StateManager.StartMenu(Game);
		}

		public override void Draw(GameTime gameTime)
		{
			spriteBatch.Begin();
			spriteBatch.Draw(bg, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
			spriteBatch.End();
			
			base.Draw(gameTime);
		}

	}
}
